<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:ICSharpCode.Core.Presentation"
>
	<Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.WindowStyleKey}">
		<Setter Property="UseLayoutRounding" Value="True" />
		<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
		<Setter Property="FlowDirection" Value="{DynamicResource {x:Static local:GlobalStyles.FlowDirectionKey}}" />
	</Style>
	
	<Style TargetType="{x:Type Window}" x:Key="{x:Static local:GlobalStyles.DialogWindowStyleKey}">
		<Setter Property="UseLayoutRounding" Value="True" />
		<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
		<Setter Property="FlowDirection" Value="{DynamicResource {x:Static local:GlobalStyles.FlowDirectionKey}}" />
		<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
		<Setter Property="ShowInTaskbar" Value="False" />
	</Style>
	
	<x:StaticExtension x:Key="{x:Static local:GlobalStyles.FlowDirectionKey}" MemberType="FlowDirection" Member="LeftToRight" />
	
	<Style TargetType="{x:Type Button}" x:Key="{x:Static local:GlobalStyles.ButtonStyleKey}">
		<Setter Property="MinWidth" Value="73" />
		<!-- <Setter Property="Height" Value="21" /> height implicit using text height+padding-->
		<Setter Property="Padding" Value="9,1,9,1" />
	</Style>
	
	<Style TargetType="ToggleButton" x:Key="{x:Static local:GlobalStyles.WordWrapCheckBoxStyleKey}">
		<Setter Property="ContentTemplate">
			<Setter.Value>
				<DataTemplate>
					<AccessText Text="{Binding}" TextWrapping="WrapWithOverflow" />
				</DataTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<Style TargetType="{x:Type Image}" x:Key="{x:Static local:ToolBarService.ImageStyleKey}">
		<Style.Triggers>
			<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ButtonBase}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
				<Setter Property="Opacity" Value="0.30" />
			</DataTrigger>
		</Style.Triggers>
	</Style>
	
	<!-- Colors for DropDownButton and SplitButton -->
	<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}" Color="#FF0A246A"/>
	<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}" Color="#FFB6BDD2"/>
	<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:SplitButton}, PressedBackground}" Color="#FF8592B5"/>
	
	<!-- Style and Template for DropDownButton -->
	<Style TargetType="{x:Type local:DropDownButton}">
		<Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
		<Setter Property="Control.Padding" Value="2,2,2,2"/>
		<Setter Property="Border.BorderThickness" Value="1,1,1,1"/>
		<Setter Property="Panel.Background" Value="Transparent"/>
		<Setter Property="Border.BorderBrush" Value="Transparent"/>
		<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
		<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
		<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
		<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="local:DropDownButton"
				                 xmlns:s="clr-namespace:System;assembly=mscorlib">
					<Border
						BorderThickness="{TemplateBinding Border.BorderThickness}"
						BorderBrush="{TemplateBinding Border.BorderBrush}"
						Background="{TemplateBinding Panel.Background}"
						Name="OuterBorder"
						SnapsToDevicePixels="True"
					>
						<StackPanel Orientation="Horizontal">
							<ContentPresenter
								Margin="{TemplateBinding Control.Padding}"
								Content="{TemplateBinding ContentControl.Content}"
								ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
								ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
								HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
								VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
								SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
							<Path Margin="0,2,2,2"
							      Data = "M0,0 L1,0 0.5,1 z"
							      Fill = "{TemplateBinding TextElement.Foreground}"
							      Width = "7"
							      Height = "3.5"
							      Stretch = "Fill"/>
						</StackPanel>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="UIElement.IsMouseOver" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}" />
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/>
						</Trigger>
						<Trigger Property="UIElement.IsKeyboardFocused" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}"/>
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/>
						</Trigger>
						<Trigger Property="UIElement.IsEnabled" Value="False">
							<Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
						</Trigger>
						<Trigger Property="local:DropDownButton.IsDropDownMenuOpen" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
							<Setter Property="Border.BorderThickness" TargetName="OuterBorder" Value="1,1,1,0" />
							<Setter Property="Border.Padding" TargetName="OuterBorder" Value="0,0,0,1" />
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="Transparent"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<!-- Style and Template for SplitButton -->
	<Style TargetType="{x:Type local:SplitButton}">
		<Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
		<Setter Property="Control.Padding" Value="2,2,2,2"/>
		<Setter Property="Border.BorderThickness" Value="1,1,1,1"/>
		<Setter Property="Panel.Background" Value="Transparent"/>
		<Setter Property="Border.BorderBrush" Value="Transparent"/>
		<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
		<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
		<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
		<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="local:SplitButton"
				                 xmlns:s="clr-namespace:System;assembly=mscorlib">
					<Border
						BorderThickness="{TemplateBinding Border.BorderThickness}"
						BorderBrush="{TemplateBinding Border.BorderBrush}"
						Background="{TemplateBinding Panel.Background}"
						Name="OuterBorder"
						SnapsToDevicePixels="True"
					>
						<StackPanel Orientation="Horizontal">
							<ContentPresenter
								Margin="{TemplateBinding Control.Padding}"
								Content="{TemplateBinding ContentControl.Content}"
								ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
								ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
								HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
								VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
								SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
							<Border
								Name="PART_DropDownArrow"
								BorderThickness="1,0,0,0"
								BorderBrush="{Binding ElementName=OuterBorder, Path=BorderBrush}"
								SnapsToDevicePixels="True"
							>
								<Path Margin="2"
								      Data = "M0,0 L1,0 0.5,1 z"
								      Fill = "{TemplateBinding TextElement.Foreground}"
								      Width = "7"
								      Height = "3.5"
								      Stretch = "Fill"/>
							</Border>
						</StackPanel>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="UIElement.IsMouseOver" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}" />
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/>
							<Setter Property="Panel.Background" TargetName="PART_DropDownArrow" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/>
						</Trigger>
						<Trigger Property="UIElement.IsKeyboardFocused" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}" />
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/>
							<Setter Property="Panel.Background" TargetName="PART_DropDownArrow" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}}"/>
						</Trigger>
						<Trigger Property="ButtonBase.IsPressed" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}}" />
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="{DynamicResource {ComponentResourceKey {x:Type local:SplitButton}, PressedBackground}}"/>
						</Trigger>
						<Trigger Property="UIElement.IsEnabled" Value="False">
							<Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
						</Trigger>
						<Trigger Property="local:SplitButton.IsDropDownMenuOpen" Value="True">
							<Setter Property="Border.BorderBrush" TargetName="OuterBorder" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
							<Setter Property="Border.BorderBrush" TargetName="PART_DropDownArrow" Value="Transparent" />
							<Setter Property="Border.BorderThickness" TargetName="OuterBorder" Value="1,1,1,0" />
							<Setter Property="Border.Padding" TargetName="OuterBorder" Value="0,0,0,1" />
							<Setter Property="Panel.Background" TargetName="OuterBorder" Value="Transparent"/>
							<Setter Property="Panel.Background" TargetName="PART_DropDownArrow" Value="Transparent"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<!-- SortableGridViewColumn.
		Displays an up arrow or down arrow in the column header when the grid is sorted using that column.
	-->
	<local:ColumnSortDirectionToVisibilityConverter x:Key="ColumnSortDirectionToVisibilityConverter"/>
	
	<DataTemplate x:Key="{ComponentResourceKey {x:Type local:SortableGridViewColumn}, ColumnHeaderTemplate}">
		<StackPanel Orientation="Horizontal">
			<TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
			<Path x:Name="upArrow"
			      Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static local:ColumnSortDirection.Ascending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}"
			      StrokeThickness = "1"
			      Fill            = "Gray"
			      Data            = "M 5,10 L 15,10 L 10,5 L 5,10"/>
			<Path x:Name="downArrow"
			      Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static local:ColumnSortDirection.Descending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}"
			      StrokeThickness = "1"
			      Fill            = "Gray"
			      Data            = "M 5,5 L 10,10 L 15,5 L 5,5"/>
		</StackPanel>
	</DataTemplate>
	
	<Style x:Key="{x:Static local:GlobalStyles.ListBoxItemFocusHighlightStyleKey}" TargetType="{x:Type ListBoxItem}">
		<!-- This style replaces the default ListBoxItem template with one that highlights the focused item instead of the selected item -->
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBoxItem}">
					<Border Name="Bd"
					        Background="{TemplateBinding Background}"
					        BorderBrush="{TemplateBinding BorderBrush}"
					        BorderThickness="{TemplateBinding BorderThickness}"
					        Padding="{TemplateBinding Padding}"
					        SnapsToDevicePixels="true">
						<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
							VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
							SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsKeyboardFocusWithin"
						         Value="true">
							<Setter TargetName="Bd"
							        Property="Background"
							        Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
							<Setter Property="Foreground"
							        Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<Style x:Key="{x:Static local:GlobalStyles.ListViewItemFocusHighlightStyleKey}" TargetType="{x:Type ListViewItem}">
		<!-- This style replaces the default ListViewItem template with one that highlights the focused item instead of the selected items -->
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListViewItem}">
					<Border Name="Bd"
					        Background="{TemplateBinding Background}"
					        BorderBrush="{TemplateBinding BorderBrush}"
					        BorderThickness="{TemplateBinding BorderThickness}"
					        Padding="{TemplateBinding Padding}"
					        SnapsToDevicePixels="true">
						<GridViewRowPresenter Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}"/>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsKeyboardFocusWithin"
						         Value="true">
							<Setter TargetName="Bd"
							        Property="Background"
							        Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
							<Setter Property="Foreground"
							        Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>